/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _OLA_ERROR_H_
#define _OLA_ERROR_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    /* [-1100,-1000) tls错误码 */
    OLA_TLS_TCP_SEND_ERR = -1100, /* TCP发送失败 */
    OLA_TLS_CONN_DNS_TIMEOUT,
    OLA_TLS_ERR_CONN_SOCKET_ERROR,
    OLA_TLS_ERR_DNS_RESOLVE_TIMEOUT,
    OLA_TLS_ERR_TCP_STATE_TIMEOUT,
    OLA_TLS_ERR_SEND_OVERTIME,
    OLA_TLS_ERR_READ_OVERTIME,
    /* [-1000,-900) 外部组件错误码 */
    OLA_CJSON_ERR_CREATE_OBJECT = -1000,
    OLA_CJSON_ERR_PARSE,
    OLA_CJSON_ERR_GET_STRING,
    OLA_CJSON_ERR_GET_NUMBER,
    OLA_CJSON_ERR_GET_OBJECT,
    OLA_CJSON_ERR_PRINT_UNFORMATTED,
    OLA_CJSON_ERR_ADD_STRING,
    OLA_CJSON_ERR_ADD_NUMBER,
    OLA_MBEDTLS_ERR_INIT,
    OLA_MBEDTLS_ERR_GEN_RANDOM,
    OLA_MBEDTLS_ERR_GET_BASE64_SIZE,
    OLA_MBEDTLS_ERR_BASE64_ENCODE,
    OLA_MBEDTLS_ERR_BASE64_DECODE,
    OLA_MBEDTLS_ERR_COMPUTE_HMAC,
    OLA_MBEDTLS_ERR_SHA256,
    OLA_MBEDTLS_ERR_SIGNATURE,
    OLA_MBEDTLS_ERR_SSL_SEND,
    OLA_MBEDTLS_ERR_SSL_READ,
    OLA_MBEDTLS_ERR_ENTROPY_ADD_SOURCE,
    OLA_MBEDTLS_ERR_CTR_DRBG_SEED,
    OLA_MBEDTLS_ERR_SSL_CONFIG_DEFAULTS,
    OLA_MBEDTLS_ERR_SSL_CONF_MAX_FRAG_LEN,
    OLA_MBEDTLS_ERR_X509_CRT_PARSE,
    OLA_MBEDTLS_ERR_SSL_SETUP,
    OLA_MBEDTLS_ERR_SSL_SET_HOSTNAME,
    OLA_MBEDTLS_ERR_SSL_HANDSHAKE,
    OLA_MBEDTLS_ERR_SSL_HANDSHAKE_TIMEOUT,
    /* [-900,-800) 平台适配层错误码 */
    OLA_SOCKET_ERR_FD_INVALID = -900,
    OLA_SOCKET_ERR_BIND_FAILED,
    OLA_SOCKET_ERR_JOIN_MULTI_GROUP,
    OLA_SOCKET_ERR_SET_RECV_TIMEOUT,
    OLA_SOCKET_ERR_SET_SEND_TIMEOUT,
    OLA_SOCKET_ERR_SELECT,
    OLA_SOCKET_ERR_CONNECT,
    OLA_SOCKET_ERR_SENDTO,
    OLA_SOCKET_ERR_GET_ADDR_INFO,
    OLA_OS_ERR_MALLOC,
    OLA_OS_ERR_GET_TIME,
    OLA_OS_ERR_CREATE_TASK,
    OLA_OS_ERR_CREATE_MUTEX,
    OLA_OS_ERR_MUTEX_LOCK,
    /* [-800,-700) 通用组件方法错误码 */
    OLA_DEVICE_ERR_GET_INFO = -800,
    OLA_UTILS_ERR_JSON_GET_NUM,
    OLA_TIME_ERR_TIME_CONVERT,
    OLA_TIME_ERR_TIME_INIT,
    OLA_TIME_ERR_TIME_OVERFLOW,
    OLA_TIME_ERR_GIT_TIMEINFO,
    OLA_TIME_ERR_GIT_WEEKDAY,
    OLA_TIME_ERR_MONTH_INVALID,
    OLA_TIME_ERR_CREATE_MUTEX,
    OLA_TIME_ERR_MUTEX_LOCK,
    OLA_TIME_ERR_ALGO,
    OLA_TIME_ERR_TO_ONE_HOUR,
    OLA_TIME_ERR_NOT_TIMESYNC,
    OLA_TIME_ERR_TIME_SYNC,
    OLA_TIME_ERR_TIME_SYNC_ASYN,
    OLA_TIME_ERR_SNTP_TIME,
    /* [-700,-600) 安全模块错误码 */
    OLA_RANDOM_ERR_INIT = -700,
    OLA_RANDOM_ERR_ADD_SOURCE,
    OLA_RANDOM_ERR_CTR_DRBG_SEED,
    OLA_RANDOM_ERR_ENTROPY_CALLBACK,
    OLA_SECURE_ERR_AES_GCM_INVALID_KEY,
    OLA_SECURE_ERR_AES_GCM_INVALID_IV,
    OLA_SECURE_ERR_AES_GCM_INVALID_ADD,
    OLA_SECURE_ERR_AES_GCM_INVALID_DATA,
    OLA_SECURE_ERR_AES_GCM_INVALID_TAG,
    OLA_SECURE_ERR_AES_GCM_SET_KEY,
    OLA_SECURE_ERR_AES_GCM_ENCRIPT,
    OLA_SECURE_ERR_AES_GCM_DECRIPT,
    OLA_SECUREC_ERR_MEMCOPY,
    OLA_SECUREC_ERR_MEMMOVE,
    OLA_SECUREC_ERR_MEMSET,
    OLA_SECUREC_ERR_STRCPY,
    OLA_SECUREC_ERR_STRNCPY,
    OLA_SECUREC_ERR_SNPRINTF,
    OLA_SECUREC_ERR_SPRINTF,
    /* [-600,-500) COAP错误码 */
    OLA_COAP_ERR_INVALID_ARGUMENT = -600,
    OLA_COAP_ERR_HEADER_TOO_SHORT,
    OLA_COAP_ERR_VERSION_INVALID,
    OLA_COAP_ERR_INVALID_TOKEN_LEN,
    OLA_COAP_ERR_INVALID_EMPTY_MESSAGE,
    OLA_COAP_ERR_OPTION_TOO_SHORT,
    OLA_COAP_ERR_BAD_REQUEST,
    OLA_COAP_ERR_OPTION_NUM_INVALID,
    OLA_COAP_ERR_OPTION_DELTA_INVALID,
    OLA_COAP_ERR_OPTION_TOO_BIG,
    OLA_COAP_ERR_OPTION_NO_URI,
    OLA_COAP_ERR_SERVER_ERROR,
    OLA_COAP_ERR_INVALID_PACKET,
    OLA_COAP_ERR_UNKNOWN_MSG_TYPE,
    OLA_COAP_ERR_PACKET_EXCEED_MAX_PDU,
    OLA_COAP_ERR_CONTEXT_EXCEED_MAX_NUM,
    OLA_COAP_ERR_CONTEXT_INVALID,
    OLA_COAP_ERR_READ_UDP_MSG,
    OLA_COAP_ERR_INVALID_RESPONSE,
    OLA_COAP_ERR_INVALID_SESSION,
    OLA_COAP_ERR_INVALID_CONTEXT,
    OLA_COAP_ERR_BUFFER_NOT_ENOUGH,
    OLA_COAP_ERR_NO_VALID_CONTEXT,
    OLA_COAP_ERR_SESSION_OVER_MAX_NUM,
    OLA_COAP_ERR_BUILD_RESEND_ITEM,
    OLA_COAP_ERR_BUILD_REQ_ITEM,
    OLA_COAP_ERR_BUILD_RECV_ITEM,
    OLA_COAP_ERR_FIND_ASYN_ITEM,
    OLA_COAP_ERR_GET_SEND_BUFFER,
    OLA_COAP_ERR_RESEND_OVER_MAX_NUM,
    OLA_COAP_ERR_RECIEVE_MSG,
    OLA_COAP_ERR_GET_TCP_PACKET_SIZE,
    /* [-500,-400) 安全存储错误码 */
    OLA_DATA_ERR_NOT_INIT = -500,
    OLA_DATA_ERR_ALREADY_INIT,
    OLA_DATA_ERR_GET_PSK,
    OLA_DATA_ERR_GET_INFO,
    OLA_DATA_ERR_GET_KEY,
    OLA_DATA_ERR_SET_KEY,
    OLA_DATA_ERR_SET_DATA,
    OLA_DATA_ERR_GET_DATA,
    OLA_DATA_ERR_ENCRYPT,
    OLA_DATA_ERR_DECRYPT,
    OLA_DATA_ERR_RAW_READ,
    OLA_DATA_ERR_RAW_WRITE,
    OLA_DATA_ERR_INVALID_LEN,
    /* [-400,-300) 端云连接错误码 */
    OLA_AUTH_ERR = -400,
    OLA_AUTH_CERTIFICATION_ERR,
    OLA_AUTH_ERR_OTHERS,
    OLA_REGISTER_ERR,
    OLA_REGISTER_ERR_OTHERS,
    OLA_REGISTER_ERR_REGISTRY_CODE_TIMEOUT,
    OLA_LOGIN_ERR,
    OLA_LOGIN_OTHERS,
    OLA_CONNECT_ERR_URL_EMPTY,
    OLA_CONNECT_ERR_URL_INVALID,
    OLA_CONNECT_ERR_PORT_INVALID,
    OLA_CONNECT_ERR_NEW_CONTEXT,
    OLA_CONNECT_ERR_REGISTER_CONTEXT_HANDLER,
    OLA_CONNECT_ERR_CONTEXT_INVALID,
    OLA_CONNECT_ERR_RESPONSE_OVER_TIME,
    OLA_CONNECT_ERR_LOGIN_ANTI_SURGE_OVER_TIME,
    OLA_CLOUD_ERR_HEARBEAT_TIMEOUT, /* 心跳超时错误 */
    OLA_CLOUD_ERR_TOKEN_REFRESH_TIMEOUT, /* 刷新token超时 */
    OLA_CLOUD_ERR_ERRCODE, /* 云端返回异常errcode */
    OLA_LINK_ERR_CONTEXT_NULL,
    OLA_LINK_ERR_INVALID_SESSION,
    /* [-300,-200) 配网协商错误码 */
    OLA_PROV_ERR_NETCFG_NOT_INIT = -300,
    OLA_NEGO_ERR_HOOK_NULL,
    OLA_NEGO_ERR_UNPACK_REQ,
    OLA_NEGO_ERR_HANDLE_REQ,
    OLA_NEGO_ERR_PACK_RES,
    OLA_NEGO_ERR_SPEKE_SEND_DATA_TOO_LONG,
    OLA_NEGO_ERR_DECRYPT_DATA,
    OLA_NEGO_ERR_ENCRYPT_DATA,
    OLA_NETWORK_ERR_CONNECT_WIFI,
    OLA_NETWORK_ERR_NOT_CONNECT,
    /* [-200,-100) SDK主框架及API错误码 */
    OLA_SDK_ERR_NOT_INIT = -200,
    OLA_SDK_ERR_CREATE_MAIN_TASK_OVERTIME,
    OLA_SDK_ERR_ALREADY_INIT,
    OLA_SDK_ERR_ALREADY_RUNING,
    OLA_SDK_ERR_CALLBACK_NULL,
    OLA_SDK_ERR_GET_FRAMEWORK_STATE,
    OLA_API_ERR_GET_DATA,
    /* [-100,-1] 通用错误码 */
    OLA_COM_ERR_INVALID_ARGUMENT = -100,
    OLA_COM_ERR_NOT_SUPPORT,
    OLA_COM_ERR_UINT32_OVERFLOW,
    OLA_COM_ERR_EXCEED_MAX_BUF_SIZE,
    OLA_ERROR = -1,
    OLA_OK = 0,
    OLA_STATE_RUNING,       /* 用于状态机持续运行 */
    OLA_COAP_RESP_LAST_MSG, /* 标识coap返回消息用于重发 */
    OLA_COAP_RESP_NOT_RESP, /* 标识coap返回消息用于回复 */
} OlaErrorCode;

#ifdef __cplusplus
}
#endif

#endif /* _OLA_ERROR_H_ */